/**
 * @Author：ming
 * @Date：2023/10/30 4:28 PM
 * @Filename：Hot24
 */

import java.util.ArrayList;

/**
 * @author ming
 */
public class Hot24 {
    public ListNode swapPairs(ListNode head) {
        if(head==null){
            return null;
        }
        if(head.next==null){
            return head;
        }
        ArrayList<ListNode> list = new ArrayList<>();
        ListNode p = head;
        while (p!=null){
            list.add(p);
            p=p.next;
        }

        for (int i = 0; i < list.size()-1; i=i+2) {
            ListNode temp = list.get(i);
            list.set(i,list.get(i+1));
            list.set(i+1,temp);
        }

        for (int i = 0; i < list.size()-1; i++) {
            list.get(i).next =list.get(i+1);
        }
        list.get(list.size()-1).next=null;
        return list.get(0);


    }
}
